package com.prs.crm.service.sale.impl;

import java.io.Serializable;

import com.prs.crm.dao.sale.QuotationSheetDao;
import com.prs.crm.domain.sale.QuotationDetail;
import com.prs.crm.domain.sale.QuotationSheet;
import com.prs.crm.domain.stock.Product;
import com.prs.crm.domain.store.Inventory;
import com.prs.crm.service.impl.FlowServiceImpl;
import com.prs.crm.service.sale.QuotationSheetService;

public class QuotationSheetServiceImpl extends FlowServiceImpl<QuotationSheet,QuotationSheetDao > implements
		QuotationSheetService {

	@Override
	public void saveQuotation(QuotationSheet quotationsheet,
			Product[] products, String[] pronames, Double[] originalCosts,
			Double[] nowCosts, Integer[] quotationNums, Double[] rebates,
			Double[] totalPrices) {
		
		for(int i=0;i<products.length;i++){		
			QuotationDetail  detail=new QuotationDetail();
			detail.setName(pronames[i]);
			detail.setProduct(products[i]);
			detail.setOriginalCost(originalCosts[i]);
			detail.setNowCost(nowCosts[i]);
			detail.setQuotationNum(quotationNums[i]);
			detail.setRebate(rebates[i]);
			detail.setTotalPrice(totalPrices[i]);
			quotationsheet.addDetail(detail);			
		}
		
		super.save(quotationsheet);
		
		
		
	}

	public boolean valideSubmit(QuotationSheet entity) {
		
		return true;
	}

	@Override
	public QuotationDetail getQuotationDetail(Product product_id,
			QuotationSheet quotation_id) {		
		return this.getDao().getQuotationDetail(product_id, quotation_id);
	}

	@Override
	public QuotationSheet getQuotationSheet(Serializable id) {
		
		return this.getDao().getQuotationSheet(id);
	}

	@Override
	public void saveOrUpdate(QuotationDetail quotationDetail) {
		this.getDao().saveOrUpdate(quotationDetail);
		
	}

	@Override
	public void saveOrUpdateQuotationSheet(QuotationSheet quotationSheet) {
		
		this.getDao().saveOrUpdateQuotationSheet(quotationSheet);
	}
	
}
